package com.itheima.day01;

public class Ticket implements Runnable {
    private int ticket = 100;
    private Object obj = new Object();

    @Override
    public void run() {
        while (true)
            synchronized (obj) {
                if (ticket <= 0) {
                    System.out.println("票买完了");
                    break;
                } else {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    ticket--;
                    System.out.println(Thread.currentThread().getName() + "在买票，还剩下" + ticket + "张票");
                }
            }
    }
}
